var fs = require('fs');
var extend = require('node.extend');
var langLoader = function(pageName, language,  callback) {
    var commonPath = "public/lang/common/" + language + ".lang";
    var pagePath = "public/lang/" + pageName + "/" + language + ".lang";
    fs.readFile(commonPath, function(error, data) {
        var commonLang = {};
        if(!error) {
            commonLang = JSON.parse(data.toString());
        }
        fs.readFile(pagePath, function(error, data) {
            var pageLang = {};
            if(!error) {
                pageLang = JSON.parse(data.toString());
            }
            var destObject = extend(true, commonLang, pageLang);
            callback(destObject);
        });
    });
}
module.exports = langLoader;
